package com.mdp.workflow.comm.dict;

import com.mdp.core.err.BizException;
import com.mdp.core.utils.ObjectTools;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * BPM 任务的候选人策略枚举
 *
 * 例如说：分配给指定人审批
 *
 *@author 唛盟开源9哥
 */
@Getter
@AllArgsConstructor
public enum CandidateStrategy {

    ROLE("10","角色"),
    DEPT_MEMBER("20","部门的成员"), // 包括负责人
    DEPT_MANAGER("21","部门的负责人"),
    DEPT_LEADER("211","部门的上级主管领导"),
    POST("22","岗位"),
    USER("30","用户"),
    PRE_DEPT_MANAGER("31","上一步任务提交者的部门经理"),
    PRE_DEPT_LEADER("311","上一步任务提交者所属部门的上级主管领导"),
    START_DEPT_MANAGER("32","发起人部门经理"),
    START_DEPT_LEADER("321","发起人所属部门的上级主管领导"),
    START_USER_SELECT("35","发起人自选"), // 申请人自己，可在提交申请时选择此节点的审批人
    START_USER("36","转发起人"), // 任务提交者可以指定下一步执行人
    SPONSORS("37","转主办"), //
    MONITORS("38","转监控"), //
    NEXT_ASSIGNEES("39","上一步分配"), //
    USER_GROUP("40","用户组"),
    XM_TEAM_LEADER("41","项目组长"), //指向唛盟项目管理中的项目组
    XM_TEAM_MEMEBER("42","项目组员"),
    EXPRESSION("60","流程表达式"), // 表达式 ExpressionManager
    HI_WHERE("90","高级查询，自定义查询条件"),
    HI_SQL("91","自定义sql,需要给定数据源+sql"),
    ;

    /**
     * 类型
     */
    private final String strategy;
    /**
     * 描述
     */
    private final String description;

    public static CandidateStrategy of(String strategy1){
        if(ObjectTools.isEmpty(strategy1)){
            throw new BizException("strategy-required","候选人策略不能为空");
        }
        Optional<CandidateStrategy> optional = Arrays.stream(CandidateStrategy.values()).filter(k->k.getStrategy().equals(strategy1)).findAny();
        if(!optional.isPresent()){
            throw new BizException("CandidateStrategy","候选人策略不存在");
        }
        return optional.get();
    }

}
